home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 122 < prev    next >
Text File  |  1996-08-06  |  1KB  |  39 lines

  1. Path: lyra.csx.cam.ac.uk!nmm1
  2. From: nmm1@cus.cam.ac.uk (Nick Maclaren)
  3. Newsgroups: comp.std.c
  4. Subject: Re: atexit() and return from main()
  5. Date: 17 Jan 1996 10:17:52 GMT
  6. Organization: University of Cambridge, England
  7. Message-ID: <4diicg$i9e@lyra.csx.cam.ac.uk>
  8. References: <4dhfja$j50@fg70.rz.uni-karlsruhe.de>
  9. NNTP-Posting-Host: ursa.cus.cam.ac.uk
  10.  
  11. In article <4dhfja$j50@fg70.rz.uni-karlsruhe.de>, ig25@fg70.rz.uni-karlsruhe.de (Thomas Koenig) writes:
  12. |> Is the following valid C?  [ NMM is to blame for the style! ]
  13. |> 
  14. |> char *a;
  15. |> void printit() { printf("%s",a); }
  16. |> 
  17. |> int main() {
  18. |>     char buffer[]="Hello, world!\n";
  19. |>     a = buffer;
  20. |>     atexit(printit);
  21. |>     return 0;
  22. |> }
  23. |> 
  24. |> 6.1.2.4 tells me it isn't, but 5.1.2.2.3 tells me that a return
  25. |> from the initial call to main() is equivalent to an exit(), and 
  26. |> I don't see a problem when I replace the 'return 0' above with
  27. |> an 'exit(0)'.
  28.  
  29. I do.  exit() may unwind the stack before calling the atexit()
  30. functions, and that is actually the way that most C run-time
  31. systems implement close down.
  32.  
  33.  
  34. Nick Maclaren,
  35. University of Cambridge Computer Laboratory,
  36. New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
  37. Email:  nmm1@cam.ac.uk
  38. Tel.:  +44 1223 334761    Fax:  +44 1223 334679
  39.